
import { commonConstants } from 'hhlt-core/constants'
import { systemUtils} from 'hhlt-core/utils'
import { formatUtils,requestUtils} from 'hhlt-vue/utils'
import { IPageInfo} from 'hhlt-core/src/model/page/pageInfo'
import { IDataTablePager} from 'hhlt-core/src/model/page/dataTablePager'
import { VxeGridPropTypes, VxeTableDefines } from 'vxe-table'
import { IColumnInfo} from 'hhlt-core/src/model/form/column'
import { IExecuteData} from 'hhlt-core/src/model/base/resultModel'
import { FormRules } from 'element-plus'
import { fixedDatasource} from "hhlt-core/constants"
import { objectUtils } from 'hhlt-core/utils'
import { requestContextPath } from 'lxsh-cer-web-pc/src/constants'
import { ICerGroupData, ICerGroupDataQO, ICerGroupDataVO,CerGroupData } from 'lxsh-cer-web-pc/src/model/cer/cer/group-data/cer-group-data'
/**
* 分组数据维护业务实现
*/
export default {
//获取页面信息，根据不同的功能编码来加载不同的页面
getPageInfo:function(pageInfo:IPageInfo<ICerGroupData>){
  this.getColumnInfo()
},
/**
* 获取列信息
*/
getColumnInfo(successCallback?:(columnsParam:VxeGridPropTypes.Columns)=>void){
    var columns:VxeGridPropTypes.Columns = [
      { type: 'checkbox', width: 50 },
      { type: 'seq', width: 60,align:'center',title:'序号' },
      { field: 'id', title: '主键ID', visible:false },
      { field: 'groupData', title: '类别名称', showOverflow: true, sortable: true,width:'100px' },
      { field: 'remark', title: '备注', showOverflow: true, sortable: true,width:'100px' },
      { field: 'addUserName', title: '添加者名', showOverflow: true, sortable: true,width:'100px' },
      { field: 'addDate', title: '添加时间', formatter: formatUtils.formatDateDefault, showOverflow: true, sortable: true ,width:'160px'},
      { title: '操作', width: 200, slots: { default: 'operate' },fixed:'right' }
    ];
    if(successCallback){
      successCallback(columns);
    }
  },
  /**
   * 获取检索条件
   */
  getSearchCondition(successCallback:(searchCondtionParam:IColumnInfo[],queryParams:ICerGroupDataQO) => void){
    var searchCondition = [
      { columnCode: 'groupData', columnName: '类别名称', basicControlType:commonConstants.enumBasicControlType.TEXT_BOX,defaultValue:"",controlAttrValue:"" },
    ];
    var queryParam:ICerGroupDataQO = {
        id:undefined,
       /**
	    * groupData:分组
	    */
    groupData:"",
    }
    return successCallback(searchCondition,queryParam);
  },
  /**
   * 单条删除操作
   */
  doDeleteSingle(selectItem:ICerGroupDataVO,successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/groupData/deleteByLogicBatch';
    let list = new Array();
    let item:ICerGroupDataQO = {
      id:selectItem.id
    }
    list.push(item)
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 单条删除操作
   */
  doDeleteBatch(selectList:ICerGroupDataVO[],successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/groupData/deleteByLogicBatch';
    let list = new Array();
    for (let selectItem of selectList) {
      let item :ICerGroupDataVO = {
        id:selectItem.id
      };
      list.push(item);
    }
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 获取分页数据
   */
  getListByPager(queryParam:ICerGroupDataQO,pager:IDataTablePager<ICerGroupDataVO>,successCallback?:(queryResult:IExecuteData<IDataTablePager<ICerGroupDataVO>>) => void):Promise<IExecuteData<IDataTablePager<ICerGroupDataVO>>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/groupData/getListByPager';
    return  requestUtils.getListByPager(url, queryParam, pager,successCallback)
  },
  addForm(formData:ICerGroupData,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/groupData/insert";
    return requestUtils.insert(url, formData,successCallback);
  },
  updateForm(formData:ICerGroupData,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/groupData/update";
    return requestUtils.update(url, formData,successCallback);
  },
  updateEnable(formData:ICerGroupData,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/groupData/updateEnable";
    return requestUtils.update(url, formData,successCallback);
  },
  getInfoByCondition(param:ICerGroupDataQO,successCallback?:(result:IExecuteData<ICerGroupDataVO>) => void):Promise<IExecuteData<ICerGroupDataVO>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/groupData/getInfoByCondition";
    return requestUtils.getInfoByCondition(url, param,successCallback);
  },
  //获取表单项
  getFormDataItem(successCallback:(formData:ICerGroupData,verify:FormRules) => void){
    var formData:ICerGroupData = new CerGroupData()
        // 校验
    var verify:FormRules = {
        groupData: [{
            required: true,
            message: "类别名称不能为空！"
        }],
    }
    return successCallback(formData,verify)
  }
}
